package com.interview.sorting;

public class InsertSort2 {

	public static void main(String args[]) {

		int a[] = { 1, 2, 34, 67, 8, 9, 6, 7, 56, 34, 232, 99 };
		int i, j, k;
		// 打印原数据
		for (i = 0; i < a.length; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
		//
		for (i = 1; i < a.length; i++) {
			for (j = i - 1; j >= 0; j--) {
				if (a[i] > a[j]) {
					break;
				}
			}

			if (j != i - 1) {
				int temp;
				temp = a[i];
				for (k = i - 1; k > j; k--)
					a[k + 1] = a[k];
				a[k + 1] = temp;
			}
		}
		for (i = 0; i < a.length; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}
}